//
//  CellForHotVCTableViewSectionOneAndTwo.m
//  echo
//
//  Created by dllo on 16/2/25.
//  Copyright © 2016年 Danny. All rights reserved.
//

#define WIDTH [UIScreen mainScreen].bounds.size.width / 414
#define HEIGHT [UIScreen mainScreen].bounds.size.height / 736

#import "CellForHotVCTableViewSectionOneAndTwo.h"
#import "ModelForHotVCTableViewCellSectionOneAndTwo.h"
#import <SDWebImage/UIButton+WebCache.h>
#import <DKNightVersion.h>

@implementation CellForHotVCTableViewSectionOneAndTwo

- (void)dealloc{
    [_viewOfBack release];
    [_button release];
    [_labelForTop release];
    [_labelForBottom release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.viewOfBack = [[UIView alloc]init];
        [self.contentView addSubview:self.viewOfBack];
        self.viewOfBack.backgroundColor = [UIColor whiteColor];
        [self.viewOfBack release];
        
        self.button = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.viewOfBack addSubview:self.button];
        
        self.labelForTop = [[UILabel alloc]init];
        [self.viewOfBack addSubview:self.labelForTop];
        [self.labelForTop release];
        self.labelForTop.font = [UIFont fontWithName:@"ArialUnicodeMS" size:17.0];
        
        self.labelForBottom = [[UILabel alloc]init];
        [self.viewOfBack addSubview:self.labelForBottom];
        [self.labelForBottom release];
        self.labelForBottom.font = [UIFont fontWithName:@"ArialUnicodeMS" size:14.0];
        [self handleNightModel];
    }
    return self;
}

- (void)handleNightModel{
    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"夜间模式"]) {
        
        [DKNightVersionManager nightFalling];
        
    } else {
        
        [DKNightVersionManager dawnComing];
    }
    
    self.viewOfBack.dk_backgroundColorPicker = DKColorWithColors([UIColor whiteColor], [UIColor colorWithRed:17 / 256.f green:27 / 256.f blue:47 / 256.f alpha:1]);
    self.labelForTop.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor whiteColor]);
    self.labelForBottom.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor whiteColor]);
    
}

- (void)layoutSubviews{
    
    [super layoutSubviews];
    
    self.viewOfBack.frame = self.contentView.frame;
    
    self.button.frame = CGRectMake(13 * WIDTH, 15 * HEIGHT, (self.contentView.frame.size.width - 120 * WIDTH) / 5 - 6 * WIDTH, (self.contentView.frame.size.width - 120 * WIDTH) / 5 - 6 * WIDTH);

    self.labelForTop.frame = CGRectMake(80 * WIDTH, 15 * HEIGHT, self.contentView.frame.size.width - 80 * WIDTH - 15 * WIDTH, 26.4 * HEIGHT);
    self.labelForBottom.frame = CGRectMake(80 * WIDTH, 41.4 * HEIGHT, self.contentView.frame.size.width - 80 * WIDTH - 15 * WIDTH, 26.4 * HEIGHT);
    
}

- (void)passDataOfHotVCTableViewCellSectionOneAndTwo:(ModelForHotVCTableViewCellSectionOneAndTwo *)model{
    
    [self.button sd_setBackgroundImageWithURL:[NSURL URLWithString:model.pic] forState:UIControlStateNormal];
    self.labelForTop.text = model.name;
    self.labelForBottom.text = model.info;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
